package com.lambo.maven.core.utils.superHttp.utils;

import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.lambo.maven.core.utils.superHttp.SHttp;
import com.lambo.maven.core.utils.superHttp.core.ProxyProp;
import com.lambo.maven.core.utils.superHttp.entity.SHttpConfig;

/**
 * 默认 shttp 对象 SHttpDefault
 * 支持 http 代理
 * 支持 sock5 代理
 */
public class SHttpDefault {

    private static Logger logger = LoggerFactory.getLogger(SHttpDefault.class);

    private static SHttp defaul;
    private static SHttp system;
    private static SHttp sock5;
    private static SHttp gate;

    public static SHttp buildLocalSock5(SSLConnectionSocketFactory sslsf, String ip, int port) {
        SHttpConfig config = new SHttpConfig();
        config.setIsChrome(true);
        config.setProxyMode(SHttpConfig.PROXY_MODE_SOCK5);
        
        config.setProxyHost(ip);
        
        config.setProxyPort(port);
		config.setSslsf(sslsf);
        SHttp sHttp = new SHttp(config);
        return sHttp;
    }

    public static SHttp getSock5() {
        return sock5;
    }

    public static SHttp getSock5(String ip, int port) {
        return getSock5(null, ip, port);
    }

    public static SHttp getSock5(SSLConnectionSocketFactory sslsf, String ip, int port) {
        if(sock5 != null) {
            return sock5;
        }
        sock5 = buildLocalSock5(sslsf, ip, port);
        return sock5;
    }

    /**
     * 获取测试代理
     * @return
     */
    private static SHttp getTest() {
        SHttpConfig config = new SHttpConfig();
        config.setIsChrome(false);
        config.setProxyMode(SHttpConfig.PROXY_MODE_SYSTEM);
        
        config.setProxyHost("127.0.0.1");
        config.setProxyPort(808);
        config.setUsername("");
        config.setPassword("");

        system = new SHttp(config);
        return system;
    }

    public static SHttp get9800() {
        SHttpConfig config = new SHttpConfig();
        config.setIsChrome(false);
        config.setProxyMode(SHttpConfig.PROXY_MODE_SYSTEM);
        
        config.setProxyHost("10.17.192.30");
        config.setProxyPort(9800);
        config.setUsername("");
        config.setPassword("");

        system = new SHttp(config);
        return system;
    }

    // 获取系统代理
    private static SHttp proxyDouble;
    // public static SHttp getDouble() {
    //     if(proxyDouble != null) {
    //         return proxyDouble;
    //     }
    //     SHttpConfig config = new SHttpConfig();
    //     config.setIsChrome(false);
    //     config.setProxyMode(SHttpConfig.PROXY_MODE_SYSTEM);
    //     config.setShttpCore(SHttpCoreDouble.class);
    //     proxyDouble = new SHttp(config);
    //     return proxyDouble;
    // }

    public static SHttp getDefault() {
        return getDefault(null);
    };

    // 不走代理的http请求对象
    public static SHttp getDefault(SSLConnectionSocketFactory sslsf) {
        if(defaul != null) {
            return defaul;
        }
        SHttpConfig config = new SHttpConfig();
        config.setIsChrome(false);
        config.setSslsf(sslsf);
        defaul = new SHttp(config);
        return defaul;
    }

}